﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using ExtAspNet;
using GPCSC.Model;
using NickLee.Common;
using System.Data;

namespace GPCSC.Web.SHFW
{
    public partial class SYS_STZ : PageBase
    {
        int cout = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            btnDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("至少选择一项！");
            if (!IsPostBack)
            {
                f_bound();
                TZUser();
            }
        }
        protected void TZUser()
        {
            Hashtable htable = new Hashtable();
            DataSet ds = new DataSet();
            ds = new SqlReadXml().ReaderDataSet("sel_TZUSER",htable);
            if (ds != null)
            {
                if (ds.Tables.Count > 0)
                {
                    DropDownList2.DataSource = ds.Tables[0];
                    DropDownList2.DataBind();

                }
            }
        }
        protected void f_bound()
        {
            CL_USER_S user = reUser();
            DataSet ds = new CL_TZ_S().TzBoundS(user.CL_USER_SOID.ToString());
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        if (dr["isread"].ToString() == "1")
                        {
                            dr["isread"] = "已读";
                        }
                        else
                        {
                            dr["isread"] = "未读";
                            dr["CLtitle"] = "<strong style=\"font-weight:bold\">" + dr["CLtitle"].ToString() + "</strong>";
                            cout += 1;
                        }
                    }
                }
                Grid1.DataSource = ds.Tables[0];
                Grid1.DataBind();
                Label1.Text = "您尚有" + cout.ToString() + "封未读邮件";
            }

        }
        protected void Window1_Close(object sender, EventArgs e)
        {
            f_bound();
            //Response.Write("<script>alert('1')</script>");

            //ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('1')</script>");

        }
        protected void ttbSearch_Trigger1Click(object sender, EventArgs e)
        {
            f_bound();
        }

        protected void ttbSearch_Trigger2Click(object sender, EventArgs e)
        {

            //string username = ttbSearch.Text.Trim();
            //if (username == "")
            //{
            //    F_bound();
            //}
            //else
            //{
            //    Hashtable htable = new Hashtable();
            //    username = "%" + username + "%";
            //    htable.Add("@like", username);
            //    DataSet ds = new SqlReadXml().ReaderDataSet("sel_user_bylike", htable);
            //    if (ds.Tables.Count > 0)
            //    {
            //        Grid1.DataSource = ds.Tables[0];
            //        Grid1.DataBind();
            //    }
            //}
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            GPCSC.Webs.databyhtable dh = new GPCSC.Webs.databyhtable();
            Hashtable htable = new Hashtable();
            int count = Grid1.SelectedRowIndexArray.Length;
            if (count > 0)
            {
                foreach (int row in Grid1.SelectedRowIndexArray)
                {
                    htable.Clear();
                    htable.Add("isdel", 1);
                    dh.databyhtables(htable, "update", "CL_TZUSER", "CLUSid", Grid1.DataKeys[row][0].ToString());
                }
                f_bound();
                Alert.Show("删除成功!");
            }
            else
            {
                Alert.Show("至少选择一项!");
            }
        }
        protected void btnNew_Click(object sender, EventArgs e)
        {
            GPCSC.Webs.databyhtable dh = new GPCSC.Webs.databyhtable();
            Hashtable htable = new Hashtable();
            int count = Grid1.SelectedRowIndexArray.Length;
            if (count > 0)
            {
                foreach (int row in Grid1.SelectedRowIndexArray)
                {
                    htable.Clear();
                    htable.Add("isread", "1");
                    dh.databyhtables(htable, "update", "CL_TZUSER", "CLUSid", Grid1.DataKeys[row][0].ToString());
                }
                f_bound();
                Alert.Show("标记成功!");
            }
            else
            {
                Alert.Show("至少选择一项!");
            }
        }
        public CL_USER_S reUser()
        {

            byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
            Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
            CL_USER_S users = (GPCSC.Model.CL_USER_S)userInfoTable["SYS_USER"];
            return users;
        }


        protected string GetEditUrl(object id,object ids)
        {
            //IsRead(ids.ToString());
            //f_bound();
            return "javascript:" + Window1.GetShowReference("C_View.aspx?id=" + id + "&ids=" + ids);
        }
        protected void IsRead(string ids )
        {
           
            Hashtable htable = new Hashtable();
            GPCSC.Webs.databyhtable dh = new GPCSC.Webs.databyhtable();
            htable.Clear();
            htable.Add("isread", 1);
            dh.databyhtables(htable, "update", "CL_TZUSER", "CLUSid", ids);

        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string value = DropDownList1.SelectedValue.ToString();
            if (value == "0")
            {
                f_bound();
            }
                //未读
            else if (value == "1")
            {
                CL_USER_S user = reUser();
                DataSet ds = new CL_TZ_S().TzBoundS(user.CL_USER_SOID.ToString(),"0");
                if (ds.Tables.Count > 0)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            if (dr["isread"].ToString() == "1")
                            {
                                dr["isread"] = "已读";
                            }
                            else
                            {
                                dr["isread"] = "未读";
                            }
                        }
                    }
                    Grid1.DataSource = ds.Tables[0];
                    Grid1.DataBind();
                }
            }
            else if (value == "2")
            {
                CL_USER_S user = reUser();
                DataSet ds = new CL_TZ_S().TzBoundS(user.CL_USER_SOID.ToString(), "1");
                if (ds.Tables.Count > 0)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            if (dr["isread"].ToString() == "1")
                            {
                                dr["isread"] = "已读";
                            }
                            else
                            {
                                dr["isread"] = "未读";
                            }
                        }
                    }
                    Grid1.DataSource = ds.Tables[0];
                    Grid1.DataBind();
                }
            }

        }

        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            string ids = DropDownList2.SelectedValue.ToString();
            Hashtable htable = new Hashtable();
              CL_USER_S user = reUser();
            htable.Add("@fsuserid",ids);

            htable.Add("@userid",user.CL_USER_SOID.ToString());
            DataSet ds = new DataSet();
            ds = new SqlReadXml().ReaderDataSet("sel_TZUSER_byfsuserid", htable);
            if (ds != null)
            {
                if (ds.Tables.Count > 0)
                {
                    Grid1.DataSource = ds.Tables[0];
                    Grid1.DataBind();
                }
            }
        }





    }
}